﻿using System.Net;
using System.Resources;
using System.Windows.Markup;
using JetBrains.Annotations;

#region Honorbuddy

using Styx;
using Styx.Common;
using Styx.CommonBot;
using Styx.CommonBot.Routines;
using Styx.Helpers;
using Styx.Pathing;
using Styx.TreeSharp;
using Styx.WoWInternals;
using Styx.WoWInternals.WoWObjects;
using CommonBehaviors.Actions;
using Action = Styx.TreeSharp.Action;
#endregion

#region System
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media;
#endregion

namespace Simcraft
{
    public partial class SimcraftImpl 
    {


        public static Composite WarriorBuffs()
        {
            return new PrioritySelector(
                new Decorator(ret => Me.IsDead || Me.IsGhost || Me.IsCasting || Me.IsChanneling || Me.IsFlying, new ActionAlwaysSucceed())
            );
        }

        public static Composite WarriorPvPCombat()
        {
            return new PrioritySelector(
                new Decorator(ret => SpellManager.HasSpell("Bloodthirst"), FuryPvP())
                //new Decorator(ret => SpellManager.HasSpell("Shield Slam") && Buff["Gladiator Stance"].Down, Protection())
                );
        }

        public static Composite FuryPvP()
        {
            return new PrioritySelector(
                Cast("Bloodthirst"),
                Cast("Execute", ret => (Buff["Sudden Death"].Up && Buff["Sudden Death"].Remains < 2) || Target.Health.Percent < 20),
                Cast("Wild Strike", ret => Buff["Bloodsurge"].Up),
                Cast("Execute", ret => Buff["Sudden Death"].Up),
                Cast("Raging Blow", ret => Buff["Raging Blow!"].Up),
                Cast("Wild Strike", ret => Rage > 100),
                Cast("Victory Rush")
            );
        }

        #region PvE
        public static Composite WarriorCombat()
        {
            return new PrioritySelector(
                new Decorator(ret => SpellManager.HasSpell("Bloodthirst"), Fury())
                //new Decorator(ret => SpellManager.HasSpell("Shield Slam") && Buff["Gladiator Stance"].Down, Protection())
                );
        }


        public static Composite Fury()
        {
            return new PrioritySelector(

                Cast("Berserker Rage", ret => Buff["Enrage"].Down || (Talent["Unquenchable Thirst"].Enabled&&Buff["Raging Blow"].Down)),
                CallActionList(FurySingleTarget(), ret => false),
                Cast("Recklessness", ret => ((Target.Health.Percent<20||CooldownsEnabled())&&(Buff["Bloodbath"].Up||!Talent["Bloodbath"].Enabled))||Talent["Anger Management"].Enabled),
                Cast("Avatar", ret => Buff["Recklesness"].Up || Target.TimeToDie < 30),
                CallActionList(FurySingleTarget(), ret => ActiveEnemies == 1),
                CallActionList(FuryTwoTarget(), ret => ActiveEnemies == 2),
                CallActionList(FuryThreeTarget(), ret => ActiveEnemies == 3),
                CallActionList(FuryAoe(), ret => ActiveEnemies > 3)
            );
        }



        public static Composite FurySingleTarget()
        {
            return new PrioritySelector(
                Cast("Bloodbath"),
                Cast("Recklessness", ret => Target.Health.Percent<20),
                Cast("Wild Strike", ret => Rage>110&&Target.Health.Percent>20),
                Cast("Bloodthirst", ret => (!Talent["Unquenchable Thirst"].Enabled&&Rage<80)||Buff["Enrage"].Down),
                CastLoc("Ravager", ret => Buff["Bloodbath"].Up||!Talent["Bloodbath"].Enabled),
                Cast("Execute", ret => Buff["Sudden Death"].Up),
                Cast("Siegebreaker"),
                Cast("Storm Bolt"),
                Cast("Wild Strike", ret => Buff["Bloodsurge"].Up),
                Cast("Execute", ret => Buff["Enrage"].Up),
                Cast("Dragon Roar", ret => Buff["Bloodbath"].Up||!Talent["Bloodbath"].Enabled),
                Cast("Raging Blow", ret => Buff["Raging Blow!"].Up&&Target.Health.Percent>20),
                Cast("Wild Strike", ret => Buff["Enrage"].Up),
                Cast("Shockwave", ret => !Talent["Unquenchable Thirst"].Enabled),
                Cast("Impending Victory",ret => !Talent["Unquenchable Thirst"].Enabled && Target.Health.Percent >20),
                Cast("Bloodthirst")
            );
        }

        public static Composite FuryTwoTarget()
        {
            return new PrioritySelector(
                Cast("Bloodbath"),
                CastLoc("Ravager", ret => Buff["Bloodbath"].Up || !Talent["Bloodbath"].Enabled),
                Cast("Dragon Roar", ret => Buff["Bloodbath"].Up||!Talent["Bloodbath"].Enabled),
                Cast("Bladestorm", ret => Buff["Enrage"].Up),
                Cast("Bloodthirst", ret => Buff["Enrage"].Down||Rage<50||Buff["Raging Blow"].Down),
                Cast("Execute", ret => UnfriendlyUnits.Count(u => u.HealthPercent < 20) > 0, UnfriendlyUnits.FirstOrDefault(u => u.HealthPercent < 20)),
                Cast("Execute", ret => Target.Health.Percent<20||Buff["Sudden Death"].Up),
                Cast("Raging Blow", ret => Buff["Meat Cleaver"].Up),
                Cast("Whirlwind", ret => !Buff["Meat Cleaver"].Up),
                Cast("Wild Strike", ret => Buff["Bloodsurge"].Up&&Rage>75),
                Cast("Bloodthirst"),
                Cast("Whirlwind", ret => Rage.Missing < 20),
                Cast("Wild Strike", ret => Buff["Bloodsurge"].Up)
            );
        }



        public static Composite FuryThreeTarget()
        {
            return new PrioritySelector(
                Cast("Bloodbath"),
                CastLoc("Ravager", ret => Buff["Bloodbath"].Up || !Talent["Bloodbath"].Enabled),
                Cast("Bladestorm", ret => Buff["Enrage"].Up),
                Cast("Bloodthirst", ret => Buff["Enrage"].Down||Rage<50||Buff["Raging Blow"].Down),
                Cast("Raging Blow", ret => Buff["Meat Cleaver"].Stack >=2),
                Cast("Execute", ret => Buff["Sudden Death"].Up),
                Cast("Execute", ret => UnfriendlyUnits.Count(u => u.HealthPercent < 20) > 0, UnfriendlyUnits.FirstOrDefault(u => u.HealthPercent < 20)),
                Cast("Dragon Roar", ret => Buff["Bloodbath"].Up||!Talent["Bloodbath"].Enabled),
                Cast("Whirlwind"),
                Cast("Bloodthirst"),
                Cast("Wild Strike", ret => Buff["Bloodsurge"].Up)
            );
        }

        public static Composite FuryAoe()
        {
            return new PrioritySelector(
                Cast("Bloodbath"),
                CastLoc("Ravager", ret => Buff["Bloodbath"].Up||!Talent["Bloodbath"].Enabled),
                Cast("Raging Blow", ret => Buff["Meat Cleaver"].Stack >=3&&Buff["Enrage"].Up),
                Cast("Bloodthirst", ret => Buff["Enrage"].Down||Rage<50||Buff["Raging Blow"].Down),
                Cast("Raging Blow", ret => Buff["Meat Cleaver"].Stack >=3),
                Cast("Recklesness", ret => Cooldown["Bladestorm"].Up),
                Cast("Bladestorm", ret => Buff["Enrage"].Remains>6),
                Cast("Whirlwind"),
                Cast("Execute", ret => Buff["Sudden Death"].Up),
                Cast("Dragon Roar", ret => Buff["Bloodbath"].Up||!Talent["Bloodbath"].Enabled),
                Cast("Bloodthirst"),
                Cast("Wild Strike", ret => Buff["Bloodsurge"].Up)
            );
        }

        #region Glad
        public static Composite Gladiator()
        {
            return new PrioritySelector(

                Cast("Bloodbath", ret => true),
                Cast("Avatar", ret => true),
                Cast("Berserker Rage", ret => Buff["Enrage"].Down),
                Cast("Shield Charge", ret => (!Buff["Shield Charge"].Up&&Cooldown["Shield Slam"].Remains < 0.1)||Spell["Shield Charge"].Charges == 2),
                Cast("Heroic Strike", ret => ((Buff["Shield Charge"].Up||Buff["Unyielding Strikes"].Up)&&Target.Health.Percent>20)||Buff["Ultimatum"].Up&&Rage>=100||Buff["Unyielding Strikes"].Stack>4),
                new Decorator(ret => ActiveEnemies == 1, Gladiator_ST()),
                new Decorator(ret => ActiveEnemies >= 2, Gladiator_AOE())
            );
        }

        public static Composite Protection()
        {
            return new PrioritySelector(

              Cast("Bloodbath", ret => true),
              Cast("Avatar", ret => true),
              Cast("Berserker Rage", ret => Buff["Enrage"].Down),
              Cast("Heroic Strike", ret => ((Buff["Shield Charge"].Up || Buff["Unyielding Strikes"].Up) && Target.Health.Percent > 20) || Buff["Ultimatum"].Up && Rage >= 100 || Buff["Unyielding Strikes"].Stack > 4),
              new Decorator(ret => ActiveEnemies == 1, Gladiator_ST()),
              new Decorator(ret => ActiveEnemies >= 2, Gladiator_AOE())
          );          
        }

        public static Composite Gladiator_ST()
        {
            return new PrioritySelector(
                Cast("Shield Slam"),
                Cast("Revenge"),
                Cast("Execute", ret => Buff["Sudden Death"].Up),
                Cast("Storm Bolt"),
                Cast("Dragon Roar"),
                Cast("Execute", ret => Rage>60&&Target.Health.Percent<20),
                Cast("Victory Rush"),
                Cast("Devastate"),
               
                new ActionAlwaysFail()
            );
        }

        public static Composite Gladiator_AOE()
        {
            return new PrioritySelector(
                Cast("Revenge"),
                Cast("Shield Slam"),
                Cast("Dragon Roar", ret => (Buff["Bloodbath"].Up||Cooldown["Bloodbath"].Remains>10)||!Talent["Bloodbath"].Enabled),
                Cast("Storm Bolt", ret => (Buff["Bloodbath"].Up || Cooldown["Bloodbath"].Remains > 7) || !Talent["Bloodbath"].Enabled),
                Cast("Thunder Clap", ret => Debuff["Deep Wounds"].Remains<3||UnfriendlysMissingDebuff("Deep Wounds", 10) > 2),
                Cast("Bladestorm", ret => Buff["Shield Charge"].Down),
                Cast("Execute", ret => Buff["Sudden Death"].Up),
                Cast("Thunder Clap", ret => ActiveEnemies > 6),
                Cast("Victory Rush"),
                Cast("Devastate"),
                new ActionAlwaysFail()
            );
        }
        #endregion
        #endregion

    }
}
